package view.component.window
{
import flash.display.MovieClip;
import flash.errors.IllegalOperationError;
import flash.utils.Dictionary;

import framework.view.components.container.RepeaterProxy;

import view.component.window.event.NavigationChangeEvent;

/**
 * ClassifiedPaginationWindow
 * @author jliang
 * 
 */
public class ClassifiedPaginationWindowProxy extends PaginationWindowProxy
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function ClassifiedPaginationWindowProxy()
	{
		super();
	}
	
	//==========================================================================
	//  Variables
	//==========================================================================	
	protected var TYPE_MAP:Dictionary = new Dictionary(true);
	
	protected var currentType:String;
	
	protected function get navData():*
	{
		throw new IllegalOperationError("navData getter should be overrided.");
	}
	
	protected function get navItemRenderClass():Class
	{
		throw new IllegalOperationError("navItemRenderClass getter should be overrided.");
	}
	
	protected function get currentTypeData():*		
	{
		return TYPE_MAP[currentType];
	}
	
	protected function get currentTypeDataLength():*		
	{
		throw new IllegalOperationError("currentTypeDataLength getter should be overrided.");
	}
	
	protected function get navRepeater():RepeaterProxy
	{
		return proxys["nav"];
	}
	//==========================================================================
	//  Overridden methods: PaginationWindowProxy
	//==========================================================================
	override protected function get proxyMapping():Array
	{
		return [ 
			{ skin:"nav", classRef: RepeaterProxy, id:"nav", renderProxyRef:navItemRenderClass }
		].concat(super.proxyMapping);
	}
	
	override public function parse(target:MovieClip):void
	{
		super.parse(target);
		
		navRepeater.data = navData;
		
		initData();
		initEventListener();
	}
	
	override protected function clickToGoPrevHandler():void
	{
		updateList(currentTypeData, currentTypeDataLength, currentPage - 1);
	}
	
	override protected function clickToGoNextHandler():void
	{
		updateList(currentTypeData, currentTypeDataLength, currentPage + 1);
	}
	
	override public function dispose():void
	{
		clearEventListener();
		super.dispose();
	}
	//==========================================================================
	//  Protected methods
	//==========================================================================
	protected function initData():void		
	{
		throw new IllegalOperationError("initData() method should be overrided.");
	}
	
	protected function initEventListener():void		
	{		
        navRepeater.skinContent.addEventListener(NavigationChangeEvent.NAV_CHANGED, navigationChangeHandler);
	}
	
	protected function clearEventListener():void		
	{		
        navRepeater.skinContent.removeEventListener(NavigationChangeEvent.NAV_CHANGED, navigationChangeHandler);
	}
	
	protected function addTypeData(key:String, source:*):void
	{
		TYPE_MAP[key] = source;
	}
	
	protected function navigationChangeHandler(event:NavigationChangeEvent):void
	{
		
	}
}
}